package com.gxar.quick.ar.server.base.model.works.mapper;

import com.gxar.quick.ar.server.base.model.works.vo.request.WorksDraftCreateRequest;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftCreateResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftInfoResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftListResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftUpdateResponse;
import com.gxar.quick.ar.server.db.model.WorksDraftEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 作品草稿转换工具
 *
 * @author Linsy
 * @version 1.0
 * @created 2023/11/8 10:45 AM
 */
@Mapper
public interface WorksDraftMapStruct {
    WorksDraftMapStruct INSTANCE = Mappers.getMapper(WorksDraftMapStruct.class);

    /**
     * 作品创建转换实体
     *
     * @param request 请求
     * @return 响应
     */
    @Mapping(target = "id", expression = "java(org.apache.commons.lang3.StringUtils.isNotBlank(request.getId()) ? Long.parseLong(request.getId()) : null)")
    @Mapping(target = "worksId", expression = "java(org.apache.commons.lang3.StringUtils.isNotBlank(request.getWorksId()) ? Long.parseLong(request.getWorksId()) : null)")
    @Mapping(target = "templateId", expression = "java(org.apache.commons.lang3.StringUtils.isNotBlank(request.getTemplateId()) ? Long.parseLong(request.getTemplateId()) : null)")
    WorksDraftEntity createToEntity(WorksDraftCreateRequest request);

    /**
     * 作品草稿转创建响应
     *
     * @param entity 实体
     * @return 响应
     */
    @Mapping(target = "worksId", expression = "java(entity.getWorksId() != null ? String.valueOf(entity.getWorksId()) : null)")
    @Mapping(target = "templateId", expression = "java(entity.getTemplateId() != null ? String.valueOf(entity.getTemplateId()) : null)")
    @Mapping(target = "workDraftId", expression = "java(String.valueOf(entity.getId()))")
    WorksDraftCreateResponse entityToCreateResponse(WorksDraftEntity entity);

    /**
     * 作品草稿转作品信息
     *
     * @param entity 实体
     * @return 作品信息
     */
    @Mapping(target = "worksId", expression = "java(entity.getWorksId() != null ? String.valueOf(entity.getWorksId()) : null)")
    @Mapping(target = "templateId", expression = "java(entity.getTemplateId() != null ? String.valueOf(entity.getTemplateId()) : null)")
    @Mapping(target = "workDraftId", expression = "java(String.valueOf(entity.getId()))")
    @Mapping(target = "userId", expression = "java(String.valueOf(entity.getUserId()))")
    WorksDraftInfoResponse entityToInfoResponse(WorksDraftEntity entity);

    /**
     * 草稿实体转列表
     *
     * @param entity 实体
     * @return 列表
     */
    @Mapping(target = "worksId", expression = "java(entity.getWorksId() != null ? String.valueOf(entity.getWorksId()) : null)")
    @Mapping(target = "templateId", expression = "java(entity.getTemplateId() != null ? String.valueOf(entity.getTemplateId()) : null)")
    @Mapping(target = "workDraftId", expression = "java(String.valueOf(entity.getId()))")
    WorksDraftListResponse entityToListResponse(WorksDraftEntity entity);

    /**
     * 草稿实体转列表响应
     *
     * @param worksDraftEntities 实体列表
     * @return 响应
     */
    List<WorksDraftListResponse> entityToListResponses(List<WorksDraftEntity> worksDraftEntities);

    /**
     * 实体转更新响应
     *
     * @param entity 更新实体
     * @return 响应
     */
    @Mapping(target = "worksId", expression = "java(entity.getWorksId() != null ? String.valueOf(entity.getWorksId()) : null)")
    @Mapping(target = "templateId", expression = "java(entity.getTemplateId() != null ? String.valueOf(entity.getTemplateId()) : null)")
    @Mapping(target = "workDraftId", expression = "java(String.valueOf(entity.getId()))")
    @Mapping(target = "userId", expression = "java(String.valueOf(entity.getUserId()))")
    WorksDraftUpdateResponse entityToUpdateResponse(WorksDraftEntity entity);
}
